﻿using System;
using System.Collections.Generic;

using System.Web;
using com.byt.webcore;
using com.byt.webcore.utils;
using com.byt.suce.db.mapper;
using com.byt.suce.db.factory;
using com.byt.suce.db.dao;

using MYLSOFT.JsonSimple;

namespace suce.wf
{
    /// <summary>
    /// Summary description for WorkFlow
    /// </summary>
    public class WorkFlow : ServletBase
    {

        private IPkgWorkflow DAO = PkgWorkflowFactory.create();

        protected override void doCommand(com.byt.webcore.ServletBase.Parameters p)
        {
            if (p.command.Equals("INBOX"))
                INBOX(p);
            else if ("HISTORICO".Equals(p.command))
                HISTORICO(p);
        }

        private void INBOX(ServletBase.Parameters p)
        {
            if (p.subcommand.Equals("GETLIST"))
            {
                PkgWorkflow.InboxGetlistParam param = DAO.newInboxGetlistParam(p.getMap());
                param.Iduser = p.iduser;
                //param.Descproc = Utils.containsParse(param.getDescproc());
                DAO.inboxGetlist(p.conn, param);
                JSONObject jo = new JSONObject();
                jo.Add("pendientes", Utils.getJSONArrayArray(param.CurPendientes));
                jo.Add("subsanados", Utils.getJSONArrayArray(param.CurSubsanados));
                jo.Add("escritos", Utils.getJSONArrayArray(param.CurEscritos));
                jo.Add("impagos", Utils.getJSONArrayArray(param.CurImpagos));
                jo.Add("derivados", Utils.getJSONArrayArray(param.CurDerivados));
                param.CurPendientes.Close();
                param.CurSubsanados.Close();
                param.CurEscritos.Close();
                param.CurImpagos.Close();
                param.CurDerivados.Close();
                p.print(jo);

            }
            else if (p.subcommand.Equals("GETINFO"))
            {
                /*
                PPkgWorkflow.InboxGetinfoParam param = DAO.newInboxGetinfoParam(p.getMap());
                param.setIdpersona(p.iduser);
                DAO.inboxGetinfo(p.conn, param);
                JSONObject jo = new JSONObject();
                jo.put("news", Utils.getJSONArrayObject(param.getCurNews()));
                jo.put("procesotipo", Utils.getJSONArrayArray(param.getCurProcesotipo()));
                jo.put("actividades", Utils.getJSONArrayArray(param.getCurActividades()));
                p.print(jo);
                param.getCurNews().close();
                param.getCurProcesotipo().close();
                param.getCurActividades().close();
                */
            }
        }

        private void HISTORICO(Parameters p)
        {
            if ("GETLIST".Equals(p.subcommand))
            {
                PkgWorkflow.HistoricoGetlistParam param = DAO.newHistoricoGetlistParam(p.getMap());
                param.Iduser = p.iduser;
                DAO.historicoGetlist(p.conn, param);
                JSONObject jo = new JSONObject();
                jo.Add("total", param.Totalrows);
                jo.Add("items", Utils.getJSONArrayObject(param.CurOut));
                param.CurOut.Close();
                p.print(jo);

            }
        }
    }
}